<?php


namespace App\Http\Controllers\Warehouse;


use App\Http\Controllers\Controller;
use App\Http\Requests\Warehouse\Location\StoreRequest;
use App\Http\Searchs\Warehouse\LocationSearch;
use App\Repositories\Location;
use Illuminate\Http\JsonResponse;

class LocationController extends Controller
{
    /**
     * @var Location
     * @author luffyzhao@vip.126.com
     */
    private $location;

    /**
     * LocationController constructor.
     * @param Location $location
     * @author luffyzhao@vip.126.com
     */
    public function __construct(Location $location)
    {
        $this->location = $location;
    }

    /**
     * @param IndexSearch $search
     * @return JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function index(LocationSearch $search)
    {
        return $this->response(
            $this->location->paginate($search->toArray())
        );
    }

    /**
     * @param StoreRequest $request
     * @return JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function store(StoreRequest $request)
    {
        return $this->response(
            $this->location->batchCreate(
                $request->only(
                    ['column', 'row', 'layer', 'attribute', 'partition', 'status']
                )
            )
        );
    }
}
